home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / jcool01.zip / EX9_7.C < prev    next >
C/C++ Source or Header  |  1992-09-28  |  2KB  |  41 lines

  1. //
  2. // Copyright (C) 1991 Texas Instruments Incorporated.
  3. //
  4. // Permission is granted to any individual or institution to use, copy, modify,
  5. // and distribute this software, provided that this complete copyright and
  6. // permission notice is maintained, intact, in all copies and supporting
  7. // documentation.
  8. //
  9. // Texas Instruments Incorporated provides this software "as is" without
  10. // express or implied warranty.
  11. //
  12.  
  13. #include <cool/AVL_Tree.h>            // Include AVL tree class
  14. #include <cool/String.h>            // Include COOL String class
  15. #include <cool/Gen_String.h>            // Include COOL Gen_String class
  16.  
  17. #include <cool/Binary_Node.C>
  18. #include <cool/Binary_Tree.C>
  19. #include <cool/AVL_Tree.C>
  20.  
  21. static CoolGen_String text ("\n\
  22.      A programming language serves two related purposes: it provides a\n\
  23.      vehicle for the programmer to specify actions to be executed and a\n\
  24.      set of concepts for the programmer to use when thinking about what\n\
  25.      can be done.");
  26.  
  27. int main (void) {
  28.   CoolAVL_Tree<CoolString> avl1;        // Declare tree variable
  29.   CoolGen_String s;                // Temporary CoolString variable
  30.   text.compile ("[a-zA-Z]+");            // Match any alphabetical word
  31.   while (text.find ()) {            // While still more words
  32.     text.sub_string (s, text.start (), text.end ()); // Get word from paragraph
  33.     avl1.put (*(new CoolString(upcase (s))));         // And add to tree
  34.   }
  35.   //Bug here, AVL Tree is not completely balanced.
  36.   //it needs one extra balance call to match structure in manual.
  37.   //avl1.balance ();
  38.   cout << avl1;                    // Output tree structure
  39.   return (0);                    // Exit with successful status
  40. }
  41.